﻿using Inovout.Memberships.Models;
using Inovout.Repositories;
using Inovout.Security;
using NHibernate.Criterion;

namespace Inovout.Memberships.Repositories
{
    public class MembershipRepository : DataObjectRepository<Membership>
    {
        internal Membership FindByEmail(string email)
        {
            Membership membership = ComponentRegistry.Resolve<IRepository<Membership>>().Find(Restrictions.Eq("Email", email).IgnoreCase());
            if (membership == null)
            {
                return null;
            }
            return membership;
        }

        internal Membership FindFirst()
        {
            Membership membership = ComponentRegistry.Resolve<IRepository<Membership>>().Find(Restrictions.Eq("Id", 1));
            if (membership == null)
            {
                return null;
            }
            return membership;
        }

        internal bool ExistsByEmail(string email)
        {
            bool isExists = ComponentRegistry.Resolve<IRepository<Membership>>().Exists(Restrictions.Eq("Email", email).IgnoreCase());

            return isExists;
        }
    }
}
